@agentsimon2 said:
ESP Now is its own network, no web server necessary
Hi,
I did have a quick look at coding a board as a
ESP8266WebServer
and then controlling pins through a board generated webpage with html form buttons to to turn pins off/on (low/high). After being unsuccessful with the TCP Stream Control module in Isadorai.e. not getting a sustained connection, I have gone back to OSC and using Isadora to send control messages....
#include <WiFiClientSecure.h>
#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>
#include <WiFiUdp.h>
#include <ESP8266WiFiType.h>
#include <ESP8266WiFiAP.h>
#include <WiFiClient.h>
#include <WiFiServer.h>
#include <ESP8266WiFiScan.h>
#include <ESP8266WiFiGeneric.h>
#include <ESP8266WiFiSTA.h>
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
int motor0 = 10; // the pin the motor0 is attached to
int motor1 = 0; // the pin the motor1 is attached to
/* Set these to your desired credentials. */
const char *ssid = "Nerve01"; //Enter your WIFI ssid
const char *password = "****"; //Enter your WIFI password
ESP8266WebServer server(80);
/* html forms for the webpage control. */
void handleRoot() {
server.send(200, "text/html", "<form action=\"/motor0_on\" method=\"get\" id=\"form1\"></form><button type=\"submit\" form=\"form1\" value=\"On\">M0-On</button><form action=\"/motor0_off\" method=\"get\" id=\"form2\"></form><button type=\"submit\" form=\"form2\" value=\"Off\">M0-Off</button><form action=\"/motor1_on\" method=\"get\" id=\"form3\"></form><button type=\"submit\" form=\"form3\" value=\"On\">M1-On</button><form action=\"/motor1_off\" method=\"get\" id=\"form4\"></form><button type=\"submit\" form=\"form4\" value=\"Off\">M1-Off</button>");
}
void handleSave() {
if (server.arg("pass") != "") {
Serial.println(server.arg("pass"));
}
}
void setup() {
pinMode(motor0, OUTPUT);
pinMode(motor1, OUTPUT);
delay(3000);
Serial.begin(115200);
Serial.println();
Serial.print("Configuring access point...");
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP()); // look at the serial monitor for the boards IP address to use in the web browser
server.on ( "/", handleRoot );
server.on ("/save", handleSave);
server.begin();
Serial.println ( "HTTP server started" );
server.on("/motor0_on", []() {
digitalWrite(motor0, 1);
Serial.println("M0-on");
handleRoot();
});
server.on("/motor0_off", []() {
digitalWrite(motor0, 0);
Serial.println("M0-off");
handleRoot();
});
server.on("/motor1_on", []() {
digitalWrite(motor1, 1);
Serial.println("M1-on");
handleRoot();
});
server.on("/motor1_off", []() {
digitalWrite(motor1, 0);
Serial.println("M1-off");
handleRoot();
});
}
void loop() {
server.handleClient();
}